/*	kd:
	The message box is weird. We want the tip to be a fixed size. The rest
	should be filled out by whatever the shopkeeper has to say about the
	item or about you.
	
	The non-unit coordinates are measured in screen pixels, so they depend on
	your resolution. In general, we don't call this function again if the
	screen size changes... because there is no event for that and we doubt
	somebody would do this and complain over just resetting the shop. */

struct Gcs_MsgBoxCoords {
	const box_tip_pixels     = 130; /* pixels dedicated to the small info tip */
	const box_tip_pixels_2   = 0.5 * box_tip_pixels;
	const border_size        = 8;
	const inner_border_size  = 4;
	
	double m_box_x;
	double m_box_y;
	double m_box_right_x;
	double m_box_bottom_y;
	double m_tip_x;
	double m_tip_y;
	double m_item_x;
	double m_item_y;
	double m_desc_x;
	double m_desc_y;
	double m_talk_x;
	double m_talk_y;
	double m_msg_wrap;
	int    m_desc_lines;
	int    m_talk_lines;
	
	double m_box_x_unit;
	double m_box_y_unit;
	double m_box_right_x_unit;
	double m_box_bottom_y_unit;
	double m_tip_x_unit;
	double m_tip_y_unit;
	double m_item_x_unit;
	double m_item_y_unit;
	double m_desc_x_unit;
	double m_desc_y_unit;
	double m_talk_x_unit;
	double m_talk_y_unit;
	double m_right_unit;
	double m_bottom_unit;
	
	/*	Diagram of how the message box positions look:
	
	 tip x, y      item x, y
	.......................................................................
	.*            .*desc x, y                                             .
	.             .........................................................
	.             .*                                                      .
	.             .                                                       .
	.             .talk x, y                                              .
	.             .........................................................
	.             .*                                                      .
	.             .                                                       .
	.             .                                                       .
	.......................................................................
	
	*/
	
	void Init (
	double		x,
	double		y,
	TextureId	sprite_box,
	Font		ffont,
		double ui_scale		= 0.666, double font_scale = 1) {
		double font_height	= ffont.GetHeight();
		
		int width = 0;
		int height = 0;
		[width, height] = TexMan.GetSize(sprite_box);
		
		// kd: If you're wondering about the 720... at first, I was a dumbo and
		// scaled to some factor * your screen, but that doesn't cause
		// everything to be drawn at the same size
		double screen_h = 720 * ui_scale;
		double screen_w = screen_h * Screen.GetAspectRatio();
		
		// This is the box's centre in screen coordinates, not unit!
		double box_cx = x * screen_w;
		double box_cy = y * screen_h;
		
		// The box's top left corner.
		m_box_x = box_cx - 0.5 * width;
		m_box_y = box_cy - 0.5 * height;
		
		// Where the tip starts (it's close to top left).
		m_tip_x = m_box_x + border_size;
		m_tip_y = m_box_y + border_size;
		
		// Where the item title will be (the description right below).
		m_item_x = m_tip_x + box_tip_pixels + inner_border_size;
		m_item_y = m_tip_y;
		
		// And some assorted stuff on the same page.
		m_desc_x = m_item_x;
		m_talk_x = m_item_x;
		m_desc_y = m_item_y + font_height + inner_border_size;
		
		// Now we gotta find out how many lines we can fit and split them up
		// nicely. That's cuz you CAN'T scroll what the shopkeeper says, so we
		// have to guarantee that the shopkeep can say everything they need.
		double bottom_y = box_cy + 0.5 * height - border_size;
		double vert_text_space = height - 2 * border_size - inner_border_size - font_height;
		
		int lines_total = (vert_text_space - inner_border_size) / font_height;
		
		m_talk_lines    = 0.5 * lines_total;
		m_desc_lines    = lines_total - m_talk_lines;
		m_talk_y        = bottom_y - m_talk_lines * font_height;
		
		double right_x = box_cx + 0.5 * width - border_size;
		m_msg_wrap = width - 2 * border_size - inner_border_size - box_tip_pixels;
		
		// kd: I dunno how zs deals with text scaling and I'm unwilling to
		// find out lolololoashdkalsjfklasjfg
		
		m_msg_wrap -= (8.0 * 14) * width / 540;
		
		// These are in the 0 to 1 range again.
		m_box_x_unit      = m_box_x     / screen_w;
		m_box_y_unit      = m_box_y     / screen_h;
		m_desc_x_unit     = m_desc_x    / screen_w;
		m_desc_y_unit     = m_desc_y    / screen_h;
		m_item_x_unit     = m_item_x    / screen_w;
		m_item_y_unit     = m_item_y    / screen_h;
		m_talk_x_unit     = m_talk_x    / screen_w;
		m_talk_y_unit     = m_talk_y    / screen_h;
		m_tip_x_unit      = m_tip_x     / screen_w;
		m_tip_y_unit      = m_tip_y     / screen_h;
		m_right_unit      = right_x     / screen_w;
		m_bottom_unit     = bottom_y    / screen_h;
		m_box_right_x_unit  = m_box_right_x  / screen_w;
		m_box_bottom_y_unit = m_box_bottom_y / screen_h;
	}
}